package com.cn.dim.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cn.dim.dao.UserDao;
import com.cn.dim.pojo.Dep;
import com.cn.dim.pojo.User;
import com.cn.dim.service.UserService;
import com.github.pagehelper.PageHelper;
@Service("userService")
public class UserServiceImpl implements UserService{
	@Resource
	UserDao userDao;

	@Override
	public List<Map<String, Object>> queryUser(Map<String, Object> m) {
		// TODO Auto-generated method stub
		PageHelper.startPage(Integer.valueOf(m.get("pageIndex").toString()),Integer.valueOf(m.get("pageSize").toString()),true);
		return userDao.queryUser(m);
	}

	@Override
	public List<Map<String, Object>> queryDepPosName(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.queryDepPosName(m);
	}

	@Override
	public int insertUser(User u, Map<String, Object> u_r, Map<String, Object> u_d_p) {
		// TODO Auto-generated method stub
		userDao.insertUser(u);
		userDao.insertUser_Role(u_r);
		return userDao.insertUser_Dep_Pos(u_d_p);
	}

	@Override
	public List<Map<String, Object>> queryRole(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.queryRole(m);
	}
	@Override
	public List<Dep> queryDep(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.queryDep(m);
	}
	@Override
	public List<Map<String, Object>> queryPos(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.queryPos(m);
	}
	@Override
	public List<Map<String, Object>> getDep(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.getDep(m);
	}

	@Override
	public int updateUser(User u, Map<String, Object> m, Map<String, Object> u_r, Map<String, Object> u_d_p) {
		// TODO Auto-generated method stub
		userDao.updateUser(u);
		userDao.delUser_Role(m);
		userDao.delUser_Dep_Pos(m);
		userDao.insertUser_Role(u_r);
		return userDao.insertUser_Dep_Pos(u_d_p);
	}

	@Override
	public int delUser(Map<String, Object> m) {
		// TODO Auto-generated method stub
		userDao.delUser(m);
		userDao.delUser_Role(m);
		return userDao.delUser_Dep_Pos(m);
	}

	@Override
	public User queryUserById(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.queryUserById(m);
	}

	@Override
	public List<Map<String, Object>> getRole(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.getRole(m);
	}

	@Override
	public int updatePassword(User u) {
		// TODO Auto-generated method stub
		return userDao.updatePassword(u);
	}
	
	//excel导入逻辑
	@Override
	public int importUser(List<User> userList,
			List<Map<String, Object>> u_d_pList,
			List<Map<String, Object>> u_rList) {
		// TODO Auto-generated method stub
		userDao.importUser(userList);
		userDao.importu_r(u_rList);
		return userDao.importu_d_p(u_d_pList);
	}
	
	//微信相关
	@Override
	public boolean isWxAlreadyLogin(Map<String, Object> m) {
		// TODO Auto-generated method stub
		boolean flag=true;
		User user=userDao.getWxLoginUserByOpenid(m);
		if(user==null||user.getId().equals(""))
		{
			flag=false;
		}
		return flag;
	}

	@Override
	public User getWxLoginUserByOpenid(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.getWxLoginUserByOpenid(m);
	}

	@Override
	public int bindingOpenid(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.bindingOpenid(m);
	}

	@Override
	public int wxLogOut(Map<String, Object> m) {
		// TODO Auto-generated method stub
		return userDao.wxLogOut(m);
	}
}
